package com.x.wx.mp.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMassMessageService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpMassNews;
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage;
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;

/**
 * <pre>
 *  注意：此contorller 实现WxMpMassMessageService接口，仅是为了演示如何调用所有群发消息相关操作接口，
 *      实际项目中无需这样，根据自己需要添加对应接口即可
 * </pre>
 *
 * @author Binary Wang(https://github.com/binarywang)
 */
@RestController
@RequestMapping("/wechat/mass")
public class WxMpMassController {

	@Autowired
	private WxMpService wxService;


	public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException {
		return this.wxService.getMassMessageService().massNewsUpload(news);
	}

	public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException {
		// TODO Auto-generated method stub
		return null;
	}

	public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException {
		// TODO Auto-generated method stub
		return null;
	}

	@PostMapping(value = "/massOpenIdsMessageSend")
	public WxMpMassSendResult massOpenIdsMessageSend(String req) throws WxErrorException {
		WxMpMassOpenIdsMessage message = JSON.parseObject(req, WxMpMassOpenIdsMessage.class);
		return this.wxService.getMassMessageService().massOpenIdsMessageSend(message);
	}

	public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage)
			throws WxErrorException {
		// TODO Auto-generated method stub
		return null;
	}

	public void delete(Long msgId, Integer articleIndex) throws WxErrorException {
		// TODO Auto-generated method stub

	}
}
